package com.guoxin.chapter3.waitnotify.firstnotify;

/**
 * @author guoxin
 * @date 2019年8月22日
 */
public class MyRun {
	private static Object lock = new Object();
	private static Runnable runnable1 = new Runnable() {
		public void run() {
			try {
				synchronized (lock) {
					System.out.println("begin wait()");
					lock.wait();
					System.out.println("end wait()");
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	};

	private static Runnable runnable2 = new Runnable() {
		public void run() {
			try {
				synchronized (lock) {
					System.out.println("begin notify()");
					lock.notify();
					System.out.println("end notify()");
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	};

	public static void main(String[] args) {
		//正常情况
//		new Thread(runnable1).start();
//		new Thread(runnable2).start();
		
		//通知过早
		new Thread(runnable2).start();
		new Thread(runnable1).start();
	}

}
